home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue31 / clinic / RichEdtU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-12-11  |  1.7 KB  |  79 lines

  1. unit RichEdtU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, Buttons;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     reSource: TRichEdit;
  12.     reDest: TRichEdit;
  13.     btnFont: TSpeedButton;
  14.     dlgFont: TFontDialog;
  15.     btnCopy: TSpeedButton;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure btnFontClick(Sender: TObject);
  20.     procedure btnCopyClick(Sender: TObject);
  21.     procedure AlternateSave(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.DFM}
  34.  
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. begin
  37.   reSource.SelStart := 10;
  38.   reSource.SelLength := 5;
  39.   reSource.SelAttributes.Color := clMaroon;
  40.   reSource.SelAttributes.Size := 24
  41. end;
  42.  
  43. procedure TForm1.btnFontClick(Sender: TObject);
  44. begin
  45.   dlgFont.Font.Assign(reSource.SelAttributes);
  46.   if dlgFont.Execute then
  47.     reSource.SelAttributes.Assign(dlgFont.Font)
  48. end;
  49.  
  50. procedure TForm1.btnCopyClick(Sender: TObject);
  51. var
  52.   stmStorage: TMemoryStream;
  53. begin
  54.   stmStorage := TMemoryStream.Create;
  55.   try
  56.     reSource.Lines.SaveToStream(stmStorage);
  57.     stmStorage.Position := 0;
  58.     reDest.Lines.LoadFromStream(stmStorage)
  59.   finally
  60.     stmStorage.Free
  61.   end
  62. end;
  63.  
  64. procedure TForm1.AlternateSave(Sender: TObject);
  65. var
  66.   PathName, FileName: array[0..Max_Path] of Char;
  67. begin
  68.   Win32Check(Bool(GetTempPath(SizeOf(PathName), PathName)));
  69.   Win32Check(Bool(GetTempFileName(PathName, '~XX', 0, FileName)));
  70.   try
  71.     reSource.Lines.SaveToFile(FileName);
  72.     reDest.Lines.LoadFromFile(FileName)
  73.   finally
  74.     DeleteFile(FileName)
  75.   end
  76. end;
  77.  
  78. end.
  79.